
Public Module performance

    Public Class performanceCounterCategories
        Public Const process As String = "process"
        Public Const processor As String = "Processor"
        Public Const memory As String = "Memory"
    End Class

    Public Class performanceCounterCounters
        Public Const processorTime As String = "% Processor Time"
        Public Const availableMBytes As String = "Available MBytes"
        Public Const availableBytes As String = "Available Bytes"
        Public Const workingSet As String = "Working Set"
        Public Const virtualBytes As String = "Virtual Bytes"
    End Class

    Public Class performanceCounterInstances
        Public Const total As String = "_Total"
    End Class

    Private PERFORMANCETEST As Boolean = False

    Public Function performanceCheck() As Boolean
        Return PERFORMANCETEST
    End Function

    Public Sub setperformanceCheck()
        PERFORMANCETEST = True
    End Sub

    Public Const perfCheckPointErrorType As Char = character.p

    Public Sub perfCheckPoint(Optional ByRef checkpoint As String = Nothing _
                                    , Optional ByRef msg As String = Nothing _
                                    , Optional ByVal forceOutput As Boolean = False _
                                    , Optional ByVal additionalJump As Int32 = 0)
        If forceOutput OrElse performanceCheck() Then
            Dim errmsg As String = Nothing
            If isemptystring(checkpoint) Then
                errmsg = "Performance Monitor Checkpoint"
            Else
                errmsg = checkpoint
            End If
            If Not isemptystring(msg) Then
                errmsg += ", " + msg + "."
            Else
                errmsg += "."
            End If
            additionalJump += 1
            raiseError(errmsg, errorHandle.errorType.other, perfCheckPointErrorType, , additionalJump)
        End If
    End Sub

    Public Sub perfMonitorStart(Optional ByRef msg As String = Nothing, Optional ByVal forceOutput As Boolean = False _
                                , Optional ByVal additionalJump As Int32 = 0)
        perfCheckPoint("Performance Monitor Start", msg, forceOutput, additionalJump + 1)
    End Sub

    Public Sub perfMonitorEnd(Optional ByRef msg As String = Nothing, Optional ByVal forceOutput As Boolean = False _
                                , Optional ByVal additionalJump As Int32 = 0)
        perfCheckPoint("Performance Monitor End", msg, forceOutput, additionalJump + 1)
    End Sub

End Module
